﻿USE [$(DatabaseName)]
GO
DECLARE @dir varchar(3000)

--- Setup the database instance
PRINT ''
PRINT ''
PRINT 'INITIALIZING DATABASE: [$(DatabaseName)]'
PRINT '--------------------------------------------------------------'
EXEC	dbo.spInitializeDatabaseConfiguration

--- Make the sa account the owner of the centraldba database
EXEC sp_changedbowner 'sa'

EXEC dbo.spGetBackupDirectory @backup_directory_name = @dir OUTPUT
IF SUBSTRING(@dir, 1, 1) <> '\'
	PRINT 'Please use spSetBackupDirectory to set the backup directory to the Backup UNC paths'


--- Remove old functions no longer part of this project
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fncGetBackupList]'))
	DROP FUNCTION [dbo].[fncGetBackupList]
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fncGetRecoveryPathFullDifferential]'))
	DROP FUNCTION [dbo].[fncGetRecoveryPathFullDifferential]
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fncGetRecoveryPathTransactionLog]'))
	DROP FUNCTION [dbo].[fncGetRecoveryPathTransactionLog]